package thread;

/**
 *
 */
public class SyncDemo3 {
    public static void main(String[] args) {

        StringBuffer sb = new StringBuffer();//同步安全的
        //StringBuilder sb  = new StringBuilder();//不是同步安全的
        Thread t1 = new Thread(){
          public void run(){
              for (int i=0;i<100;i++){
                  sb.append("abc");
              }
          }
        };

        Thread t2 = new Thread(){
          public void run(){
              for (int i=0;i<100;i++){
                  sb.append("def");
              }
          }
        };
        t1.start();
        t2.start();
        try {
            Thread.sleep(50);
        } catch (InterruptedException e) {
        }
        System.out.println(sb.length());
        System.out.println(sb);
    }
}
